





<template>
	<div class="school">
		<h2>学校名称：{{name}}</h2>
		<h2>学校地址：{{address}}</h2>
	</div>
</template>

<script>
import  pubsub from  "pubsub-js"

export default {
  name: "School",
  data() {
    return {
      name: "99白云学校",
      address: "广州白云"
    };
  },
  methods: {
    sendSchoolName (magName,data) {
      console.log("有人发布了hello消息，hello回调被执行了", magName, data)
    }
  },
  mounted() {
    // console.log(this.x)
    // this.$bus.$on("hello", data => {
    //   console.log("我是school组件我收到了数据", data);
    // });
    //pubsub.subscribe 订阅消息

   // this.pubid =pubsub.subscribe("hello", (magName,data)=>{//第一种写法
   //    console.log("有人发布了hello消息，hello回调被执行了",magName,data)
   //  })
    this.pubid =pubsub.subscribe("hello",this.sendSchoolName)
  },
  beforeDestroy() {
    //this.$bus.$off("hello")
    //pubsub.unsubscribe 取消 订阅消息
    pubsub.unsubscribe(this.pubid)
  },
  
};
//67
</script>

<style scoped>
.school {
  background-color: rgba(147, 228, 232, 0.5);
  margin: 10px 0;
}
</style>